<template>
	<view>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航视图 -->
		<view class="navi-list">
			<view class="navi-item" v-for="(item,i) in naviList" :key="i" @click="HandleNaviClick(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		<!-- 楼层视图 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<image :src="item.floor_title.image_src" class="floor-title"></image>
				<view class="floor-big-box">
					<navigator class="floor-left" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" :style="{
							width:item.product_list[0].image_width + 'rpx'
						}" mode="widthFix"></image>
					</navigator>
					<view class="floor-right">
						<navigator class="floor-right-item" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2!== 0" :url="item2.url">
							<image :src="item2.image_src" :style="{
								width:item2.image_width + 'rpx'
							}" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList:[],
				naviList:[],
				floorList:[]
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNaviList()
			this.getFloorsList()
		},
		methods:{
			// 获取轮播图数据
			async getSwiperList(){
				const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.meta.status!== 200) return uni.$showMsg()
				this.swiperList = res.message
			},
			// 获取导航数据
			async getNaviList(){
				const {data:res} =  await uni.$http.get('/api/public/v1/home/catitems')
				console.log(res)
				if(res.meta.status!==200) return uni.$showMsg()
				this.naviList = res.message
			},
			HandleNaviClick(item){
				console.log(item.name)
				if(item.name === '分类'){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			// 获取楼层数据
			async getFloorsList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
				console.log(res)
				if(res.meta.status!== 200) return uni.$showMsg()
				// 为请求到的数据添加跳转url
				res.message.forEach(floor=>{
					floor.product_list.forEach(product=>{
						product.url = '/subpkg/goods_list/goods_list?'+ product.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message
			}
		}
	}
</script>

<style lang="scss">
swiper{
	height: 230px;
	.swiper-item,image{
		width: 100%;
		height: 100%;
	}
}
.navi-list{
	display: flex;
	justify-content: space-around;
	padding: 15rpx 0;
	image{
		width: 115rpx;
		height: 120rpx;
	}
}
.floor-title{
	width: 100%;
	height: 60rpx;
}
.floor-right{
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;
}
.floor-big-box{
	display: flex;
	padding-left: 10rpx;
}
</style>
